<script type="text/javascript">
    $(function() {
        $.fn.dataGridOptions.formSubFun("#form",'/modules/additional/drawLottery/lotteryDoEdit.html');
    });
</script>
<form id="form" method="post" enctype="multipart/form-data">
<div class="popForm sForm">
	<div class="formitm">
		<label class="lab">名称：</label>
		<div class="ipt"><input type="text" name="name" value="${lottery.name}"class="easyui-validatebox validatebox-text" data-options="required: true, validType:'maxLength[15]'"></div>
	</div>
	<div class="formitm">
		<label class="lab">抽奖类别：</label>
		<div class="ipt">
			<select name="category" id="category">
				<option value="1" <#if lottery.category==1>selected="selected"</#if>>积分抽奖</option>
				<option value="2" <#if lottery.category==2>selected="selected"</#if>>签到抽奖</option>
			</select>
		</div>
	</div>
	<div class="formitm">
		<label class="lab">状态：</label>
		<div class="ipt">
			<select name="status" id="status">
				<option value="1" <#if lottery.type==1>selected="selected"</#if>>启用</option>
				<option value="0" <#if lottery.type==0>selected="selected"</#if>>禁用</option>
			</select>
		</div>
	</div>
	<div class="formitm">
		<label class="lab">类型：</label>
		<div class="ipt">
			<select name="type" id="type">
				<option value="1" <#if lottery.type==1>selected="selected"</#if>>积分</option>
				<option value="2" <#if lottery.type==2>selected="selected"</#if>>现金</option>
				<option value="3" <#if lottery.type==3>selected="selected"</#if>>加息券</option>
				<option value="4" <#if lottery.type==4>selected="selected"</#if>>抽奖</option>
				<option value="5" <#if lottery.type==5>selected="selected"</#if>>电影票</option>
				<option value="6" <#if lottery.type==6>selected="selected"</#if>>现金红包</option>
				<option value="9" <#if lottery.type==9>selected="selected"</#if>>虚拟红包</option>
				<option value="7" <#if lottery.type==7>selected="selected"</#if>>体验券</option>
				<option value="8" <#if lottery.type==8>selected="selected"</#if>>实物</option>
				<option value="0" <#if lottery.type==0>selected="selected"</#if>>未中奖</option>
			</select>
		</div>
	</div>

	<div  id="ruleList" style="display: none">
		<label class="lab">规则列表：</label>
		<div class="ipt">
			<select name="itemId" id="itemId">
				<option>----请选择----</option>
			</select>
		</div>
	</div>

	<div class="formitm">
		<label class="lab">中奖率：</label>
		<div class="ipt"><input type="text" value="${lottery.rate}" name="rate" class="easyui-validatebox validatebox-text" data-options="required: true,validType:'lotteryRate[0,1]'" style="width:80px;">&nbsp;介于0～1之间</div>
	</div>
	<div class="formitm" id="valueDiv">
		<label class="lab">中奖值：</label>
		<div class="ipt"><input type="text" name="value" class="easyui-validatebox validatebox-text" maxlength="6" style="width:80px;" value="${lottery.value}">&nbsp;<span id="unit">积分</span></div>
	</div>
	<div class="formitm">
		<label class="lab">位置：</label>
		<div class="ipt"><input type="text" name="pos" value="${lottery.pos}" class="easyui-validatebox validatebox-text" data-options="required: true, validType:'numOnly'">&nbsp;转盘上顺时针顺序</div>
	</div>
	<div class="formitm">
		<label class="lab">有效期类型:</label>
		<div class="ipt">
			<select name="validDayType" id="validDayType">
				<option value="1" selected="selected">天</option>
				<option value="2">月</option>
			</select>
		</div>
	</div>
	<div class="formitm">
		<label class="lab">有效期(天)：</label>
		<div class="ipt"><input type="text" name="validDay" value="${lottery.validDay}" class="easyui-validatebox validatebox-text" data-options="required: true, validType:'numOnly'">&nbsp;<span id="timeUnit">天</span></div>
	</div>
	<input type="hidden" name="addTime" value="<#if lottery.addTime?? >${lottery.addTime?string('yyyy-MM-dd HH:mm:ss')}</#if>">
	<input type="hidden" name="id" value="${lottery.id}">
</div>
</form>
<script>
	var typeVal = $("#type").val();
	if(typeVal ==1){
		$("#unit").text("积分");
	}else if(typeVal == 2){
		$("#unit").text("元");
	}else if(typeVal==3){
		$("#ruleList").show();
		$("#valueDiv").hide();
		$("#unit").text("额度加息券");
		upRateListFn();
	}else if(typeVal==4){
		$("#unit").text("次抽奖");
	}else if(typeVal==5){
		$("#unit").text("张电影票");
	}else if(typeVal==6){
		$("#unit").text("元现金红包");
	}else if(typeVal==9){
		$("#unit").text("元虚拟红包");
	}else if(typeVal==7) {
		$("#ruleList").show();
		$("#valueDiv").hide();
		$("#unit").text("元体验券");
		experienceListFn();
	}else if(typeVal==8) {
		$("#ruleList").show();
		$("#valueDiv").hide();
		$("#unit").text("");
		commodityListFn();
	}else if(typeVal==0) {
		$("#unit").text("");
	}

	$("#type").change(function(){
		var typeValSelect=$(this).val();
		switch (typeValSelect) {
			case '1' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("积分");
				break;
			case '2' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("元");
				break;
			case '3' :
				$("#valueDiv").hide();
				$("#unit").text("额度加息券");
				upRateListFn();
				break;
			case '4' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("次抽奖");
				break;
			case '5' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("张电影票");
				break;
			case '6' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("元现金红包");
				break;
			case '9' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("元虚拟红包");
				break;
			case '7' :
				$("#valueDiv").hide();
				$("#unit").text("元体验券");
				experienceListFn();
				break;
			case '8' :
				$("#valueDiv").hide();
				$("#unit").text("");
				commodityListFn();
				break;
			case '0' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("");
				break;
		}
	});

	$("#validDayType").change(function(){
		var validDayType = $(this).val();
		if(validDayType == 1) {
			$("#timeUnit").text("天")
		}else if(validDayType ==2){
			$("#timeUnit").text("月")
		}
	});
	$("#category").change(function(){
		if($("#type").val() == 8) {
			commodityListFn();
		}
	});
	//展示奖品为商品的列表
	var itemId = '${lottery.itemId}';
	function commodityListFn(){
		$.post("/modules/additional/commodity/jsonLotteryCommodityList.html",
			{
				category : $("#category").val()
			},
			function(data,status){
				var data = eval(data);
				$("#ruleList").show();
				$('#itemId option:gt(0)').remove();
				$.each(data, function(index, item){
					var str = '';
					str += '<option value="'+item.ruleId;
					if(itemId > 0 && itemId == item.ruleId) {
						str += '" selected = "selected';
					}
					str += '">' + item.ruleName+'</option>';
					$("#itemId").append($(str));//后台数据加到下拉框
				});
			}
		)
	}
	//展示加息券列表
	function upRateListFn(){
		$.post("/modules/additional/upRate/usableUpRateList.html",
				{
				},
				function(data,status){
					var data = eval(data);
					$("#ruleList").show();
					$('#itemId option:gt(0)').remove();
					$.each(data, function(index, item){
						var str = '';
						str += '<option value="'+item.ruleId;
						if(itemId > 0 && itemId == item.ruleId) {
							str += '" selected = "selected';
						}
						str += '">' + item.ruleName+'</option>';
						$("#itemId").append($(str));//后台数据加到下拉框
					});
				}
		)
	}
	//展示体验金列表
	function experienceListFn(){
		$.post("/modules/additional/experienceRule/experienceRuleJson.html",
			{
			},
			function(data,status){
				var data = eval(data);
				$("#ruleList").show();
				$('#itemId option:gt(0)').remove();
				$.each(data, function(index, item){
					var str = '';
					str += '<option value="'+item.ruleId;
					if(itemId > 0 && itemId == item.ruleId) {
						str += '" selected = "selected';
					}
					str += '">' + item.ruleName+'</option>';
					$("#itemId").append($(str));//后台数据加到下拉框
				});
			}
		)
	}
 </script>

